{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [],
   "source": [
    "import numpy as np\n",
    "import matplotlib.pyplot as plt\n",
    "from sever.data_loader.process import RLE, mask2rle, rle2mask"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [],
   "source": [
    "s = ('52349 132 52605 132 52861 132 53117 132 53373 132 53629 132 53885 132 54141 132 54397 '\n",
    "     '132 54653 132 54909 132 55134 163 55328 1248 56577 255 56833 255 57089 255 57345 255 57601 '\n",
    "     '255 57857 255 58113 255 58369 255 58625 255 58881 255 59137 254 59393 254 59681 222 60000 '\n",
    "     '159 60320 95 60639 32 293678 8 293918 24 294166 32 294422 32 294678 32 294934 32 295189 33 '\n",
    "     '295445 33 295701 33 295957 33 296213 33 296469 33 296725 33 296980 34 297236 34 297492 34 '\n",
    "     '297748 34 298004 34 298260 34 298516 34 298772 34 299027 35 299283 35 299539 35 299795 35 '\n",
    "     '300051 35 300307 35 300563 35 300818 36 301074 36 301330 36 301586 36 301842 33 302098 28 '\n",
    "     '302354 23 302609 18 302865 13 303121 8 303377 3')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "(256, 1600)\n",
      "7607\n",
      "uint8\n",
      "1\n"
     ]
    }
   ],
   "source": [
    "m1 = rle2mask(s, (1600, 256))\n",
    "print(m1.shape)\n",
    "print(m1.sum())\n",
    "print(m1.dtype)\n",
    "print(m1.max())"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "<matplotlib.image.AxesImage at 0x7f8a1411a128>"
      ]
     },
     "execution_count": 4,
     "metadata": {},
     "output_type": "execute_result"
    },
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAATEAAAD6CAYAAADJPXCrAAAABHNCSVQICAgIfAhkiAAAAAlwS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qPquqSWAtsC7JxUtd06CSfBs4VFUvL3UtS2HcIbYPOG/G9lpg/5hrGLWDSVYDdMtDS1zPoiSZoBdgj1TVY13zsugbQFV9CDxLb0yz9X5dBvxhknfoDdFckeTvab9ffRl3iL0EXJjkG0m+AnwHeGLMNYzaE8DGbn0j8PgS1rIoSQI8BOytqvtmvNV035KcleT0bv0U4CrgDRrvV1X9RVWtrarz6f2b+teq+hMa71e/xv6wa5Jr6F2/rwC2VtVfjbWAIUryKHA5vV8LOAh8D/gnYDvw68C7wA1Vdfzg/5dakt8B/g14nV+OsdxJb1ys2b4l+S16A9wr6P0PfHtV/WWSX6Phfs2U5HLgT6vq28upXyfiE/uSmuYT+5KaZohJapohJqlphpikphlikppmiElqmiEmqWmGmKSm/R/Tdp6ik6ELtAAAAABJRU5ErkJggg==\n",
      "text/plain": [
       "<Figure size 432x288 with 1 Axes>"
      ]
     },
     "metadata": {
      "needs_background": "light"
     },
     "output_type": "display_data"
    }
   ],
   "source": [
    "plt.imshow(m1)\n",
    "plt.imshow(m1[15:55, 1140:1190])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "(256, 1600)\n",
      "7607\n",
      "uint8\n",
      "1\n"
     ]
    }
   ],
   "source": [
    "rle = RLE.from_str(s)\n",
    "m2 = rle.to_mask()\n",
    "print(m2.shape)\n",
    "print(m2.sum())\n",
    "print(m2.dtype)\n",
    "print(m2.max())"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "<matplotlib.image.AxesImage at 0x7f8a1406dba8>"
      ]
     },
     "execution_count": 6,
     "metadata": {},
     "output_type": "execute_result"
    },
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAATEAAAD6CAYAAADJPXCrAAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxIB0t1+/AAAADh0RV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q2wfcM6M7bXA/jHXMGoHk6wG6JaHlrieRUkyQS/AHqmqx7rmZdE3gKr6EHiW3phm6/26BPidJO/QG6K5LMnf0n6/+jLuEHsJOD/Jt5KcAHwHeGLMNYzaE8DGbn0j8PgS1rIoSQI8BOytqvtmvNV035KckeTUbv1E4ArgDRrvV1X9SVWtrapz6f1N/VtV/R6N96tfY3/YNclV9K7fVwBbq+rPxlrAECV5FLiU3q8FHAS+C/wjsB34ReBd4PqqOnbw/ystya8D/w68zs/GWO6gNy7WbN+S/Cq9Ae4V9P4D315Vf5rkF2i4XzMluRT4w6q6ejn163h8Yl9S03xiX1LTDDFJTTPEJDXNEJPUNENMUtMMMUlNM8QkNc0Qk9S0/wP2/J6EOuMTMAAAAABJRU5ErkJggg==\n",
      "text/plain": [
       "<Figure size 432x288 with 1 Axes>"
      ]
     },
     "metadata": {
      "needs_background": "light"
     },
     "output_type": "display_data"
    }
   ],
   "source": [
    "plt.imshow(m2)\n",
    "plt.imshow(m2[15:55, 1140:1190])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "0.0\n",
      "136.0\n",
      "-1.0\n",
      "1.0\n"
     ]
    },
    {
     "data": {
      "text/plain": [
       "<matplotlib.image.AxesImage at 0x7f8a14001d30>"
      ]
     },
     "execution_count": 7,
     "metadata": {},
     "output_type": "execute_result"
    },
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAXcAAABYCAYAAAAOTbepAAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxIB0t1+/AAAADh0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uMy4xLjEsIGh0dHA6Ly9tYXRwbG90bGliLm9yZy8QZhcZAAAIUElEQVR4nO3da4xUdx3G8e/jLmBpJYCUSlkiW7Mx4pvSEkqtMUZUsDZs35hgrGKs4U1NWi9RkMTEF02smmqMUUNKDSqWEEotaW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XLXmlbSO4ljKmy4MjZJnwnNKmgqsA74x0upR8jT1+z9M3eU+SDHfdUEXxVviWkiaRFHsmyJiWxp+Ob0VI52fSuN1Zb8FWCHpeYpprA9J+kUDcw4CgxGxK13eSlH2Tcv5YeBYRLwSEeeAbcD7GpjzgvHmGuT1KZHyeOUkrQJuAz6VpjCalvNdFL/U96fnUxewV9I7GpbzktRd7ruBHkndkiYDK4HtdQRJn3hvAPoi4v7Squ3AqrS8Cni0NL5S0hRJ3UAPxQctlYqItRHRFRHzKR6v30bEHQ3M+RJwXNK709BS4HDTclJMxyyRNDX9DCyl+LylaTkvGFeuNHVzWtKSdP8+U9qmMpKWA18DVkTEv4fkb0TOiDgQEbMjYn56Pg1S7FTxUpNyXrK6P9EFbqXYM+UosK7GHO+neHv1NLAvnW4F3g7sBI6k85mlbdal3P3U8Ik58EFe31umcTmB64E96TH9FTCjoTm/CTwDHAR+TrGHRO05gYcoPgc4R1E8d15KLmBRum9HgR+S/jK94pwDFHPWF55LP2liziHrnyftLVNnznad/O8HzMwyVPe0jJmZVcDlbmaWIZe7mVmGXO5mZhlyuZuZZcjlbmaWIZe7mVmG/ge9CG4ZlUvYogAAAABJRU5ErkJggg==\n",
      "text/plain": [
       "<Figure size 432x288 with 1 Axes>"
      ]
     },
     "metadata": {
      "needs_background": "light"
     },
     "output_type": "display_data"
    }
   ],
   "source": [
    "diff = (m1.astype(np.float32) - m2.astype(np.float32))\n",
    "print(diff.sum())\n",
    "print(np.abs(diff).sum())\n",
    "print(diff.min())\n",
    "print(diff.max())\n",
    "plt.imshow(np.abs(diff))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "0.0\n",
      "136.0\n",
      "-1.0\n",
      "1.0\n"
     ]
    },
    {
     "data": {
      "text/plain": [
       "<matplotlib.image.AxesImage at 0x7f8a13f5de48>"
      ]
     },
     "execution_count": 8,
     "metadata": {},
     "output_type": "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cPjyqXi+MbTIuIPUTTTz0rbVJYzIp6IiPPp4h8pjqXcuJzJ94CvAuW9S2rL2S51l/tc4Hjp8mAaq5Wk+cBCYBdwTUSchOIXADA7Xa3O7N+n+GH8b2msaTmvA14Bfpqmjx6QdGXTckbEi8B3KQ4VeRL4Z0Q80bScJePNNTctDx2fSJ+jeIULDcspaQXwYkTsH7KqUTkvRd3lPtJcVa37Zkq6CngYuCciXrvYVUcYqzy7pNuAUxHx51Y3GWFsIh7jToq3wD+OiIXAvyimEUZT1+M5g+JVWjdwLXClpDsutskIY03Yn3i0XLXmlbSO4ljKmy4MjZJnwnNKmgqsA74x0upR8jT1+z9M3eU+SDHfdUEXxVviWkiaRFHsmyJiWxp+Ob0VI52fSuN1Zb8FWCHpeYpprA9J+kUDcw4CgxGxK13eSlH2Tcv5YeBYRLwSEeeAbcD7GpjzgvHmGuT1KZHyeOUkrQJuAz6VpjCalvNdFL/U96fnUxewV9I7GpbzktRd7ruBHkndkiYDK4HtdQRJn3hvAPoi4v7Squ3AqrS8Cni0NL5S0hRJ3UAPxQctlYqItRHRFRHzKR6v30bEHQ3M+RJwXNK709BS4HDTclJMxyyRNDX9DCyl+LylaTkvGFeuNHVzWtKSdP8+U9qmMpKWA18DVkTEv4fkb0TOiDgQEbMjYn56Pg1S7FTxUpNyXrK6P9EFbqXYM+UosK7GHO+neHv1NLAvnW4F3g7sBI6k85mlbdal3P3U8Ik58EFe31umcTmB64E96TH9FTCjoTm/CTwDHAR+TrGHRO05gYcoPgc4R1E8d15KLmBRum9HgR+S/jK94pwDFHPWF55LP2liziHrnyftLVNnznad/O8HzMwyVPe0jJmZVcDlbmaWIZe7mVmGXO5mZhlyuZuZZcjlbmaWIZe7mVmG/ge9CG4ZlUvYogAAAABJRU5ErkJggg==\n",
      "text/plain": [
       "<Figure size 432x288 with 1 Axes>"
      ]
     },
     "metadata": {
      "needs_background": "light"
     },
     "output_type": "display_data"
    }
   ],
   "source": [
    "diff = (m2.astype(np.float32) - m1.astype(np.float32))\n",
    "print(diff.sum())\n",
    "print(np.abs(diff).sum())\n",
    "print(diff.min())\n",
    "print(diff.max())\n",
    "plt.imshow(np.abs(diff))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "68"
      ]
     },
     "execution_count": 9,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "(diff == 1).sum()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {},
   "outputs": [
    {
     "ename": "ValueError",
     "evalue": "operands could not be broadcast together with shapes (130,) (131,) (130,) ",
     "output_type": "error",
     "traceback": [
      "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
      "\u001b[0;31mValueError\u001b[0m                                Traceback (most recent call last)",
      "\u001b[0;32m<ipython-input-10-48c4d5236167>\u001b[0m in \u001b[0;36m<module>\u001b[0;34m\u001b[0m\n\u001b[0;32m----> 1\u001b[0;31m \u001b[0mRLE\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mfrom_mask\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mdiff\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m",
      "\u001b[0;32m~/bb/kaggle/severstal-steel-defect-detection/sever/data_loader/process.py\u001b[0m in \u001b[0;36mfrom_mask\u001b[0;34m(cls, mask)\u001b[0m\n\u001b[1;32m    156\u001b[0m         \u001b[0mpixels\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mnp\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mconcatenate\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0;36m0\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mpixels\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0;34m[\u001b[0m\u001b[0;36m0\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m    157\u001b[0m         \u001b[0mruns\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mnp\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mwhere\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mpixels\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0;36m1\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m]\u001b[0m \u001b[0;34m!=\u001b[0m \u001b[0mpixels\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m-\u001b[0m\u001b[0;36m1\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0;36m0\u001b[0m\u001b[0;34m]\u001b[0m \u001b[0;34m+\u001b[0m \u001b[0;36m1\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m--> 158\u001b[0;31m         \u001b[0mruns\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0;36m1\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;36m2\u001b[0m\u001b[0;34m]\u001b[0m \u001b[0;34m-=\u001b[0m \u001b[0mruns\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;36m2\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m    159\u001b[0m         \u001b[0;32mreturn\u001b[0m \u001b[0mcls\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mfrom_list\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mruns\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m    160\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n",
      "\u001b[0;31mValueError\u001b[0m: operands could not be broadcast together with shapes (130,) (131,) (130,) "
     ]
    }
   ],
   "source": [
    "RLE.from_mask(diff)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "plt.imshow(diff[:80, 1100:1200])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.6.7"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
